home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 02 - Basic Game Graphics / ColorPicker Demo ƒ / ColorPickerDemo.c next >
Encoding:
C/C++ Source or Header  |  1995-03-30  |  3.6 KB  |  118 lines  |  [TEXT/MMCC]

  1. //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  2. //
  3. //    ColorPickerDemo.c
  4. //
  5. //    Simple program to display the Apple Color Picker. Places string
  6. //    describing the decimal RGB values on the Clipboard if you click OK.
  7. //
  8. //    History:
  9. //
  10. //    950225 jb: Written
  11. //    950305 jb: Cleaned up
  12. //
  13. //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  14.  
  15.  
  16. //  __#Defines________________________________________________________________________
  17. //  __#Headers________________________________________________________________________
  18. #include <Picker.h>
  19.  
  20. //  __#Protos_________________________________________________________________________
  21. //  __ Macros_________________________________________________________________________
  22. //  __ Enums__________________________________________________________________________
  23. //  __ Typedefs_______________________________________________________________________
  24. //  __ Static Protos__________________________________________________________________
  25. static void PutRGBTextIntoScrap(RGBColor *theRGB);
  26. static void ToolBoxInit(void);
  27.  
  28. //  __ Extern Globals_________________________________________________________________
  29. //  __ Static Globals_________________________________________________________________
  30. //  __ Functions______________________________________________________________________
  31.  
  32.  
  33.  
  34. //____ main __________________________________________________________________________
  35. //
  36. //    For this simple program, this is where the action is.
  37. //
  38. void main( void )
  39. {
  40. Point            where;
  41. RGBColor        originalColor = {65535,65535,65535};    //absolute white
  42. RGBColor        newColor;
  43.  
  44.     ToolBoxInit();
  45.     
  46.     where.h = where.v = -1;        //Position of -1,-1 tells Color Picker logic
  47.                                 //to center Picker dialog on best screen.
  48.  
  49.     if    ( GetColor(where, "\pColorPickerDemo", &originalColor, &newColor) )
  50.     {
  51.         PutRGBTextIntoScrap(&newColor);    //change newColor into a string and
  52.                                         //put it on the Clipboard
  53.     }
  54.     
  55. }//main
  56.  
  57.  
  58. //____ PutRGBTextIntoScrap __________________________________________________________________________
  59. //
  60. //    Given a pointer to an RGBColor, translate it into
  61. //    text (e.g. "65536, 32768, 16384") and put it
  62. //    on the Clipboard.
  63. //
  64. static void PutRGBTextIntoScrap(RGBColor *theRGB)
  65. {
  66. char            scrapStr[20];
  67. long            aLong;
  68. Str15        aStr;
  69. short        len;
  70. char             *outCharPtr;
  71. short        rgbElementCtr;
  72.  
  73.     outCharPtr = scrapStr;                //point to our output string
  74.     ZeroScrap();                        //empty current contents of desk scrap
  75.     for (rgbElementCtr = 0; rgbElementCtr < 3; rgbElementCtr++)    //for R, G, and B
  76.     {
  77.         if (rgbElementCtr == 0)            //get value of RGB element
  78.             aLong = theRGB->red;
  79.         else if (rgbElementCtr == 1)
  80.             aLong = theRGB->green;
  81.         else
  82.             aLong = theRGB->blue;
  83.         NumToString(aLong, aStr);        //convert it to a string
  84.         len = *aStr;                    //get length of Pascal string
  85.         BlockMove(aStr + 1, outCharPtr, len);    //append number's string to our output string
  86.         outCharPtr += len;                //remember where end of string is
  87.         if (rgbElementCtr < 2)            //append a comma, if appropriate
  88.         {
  89.             *outCharPtr = ',';
  90.             outCharPtr++;
  91.         }
  92.     }
  93.  
  94.     *outCharPtr = '\0';                    //zero-terminate our c-style string
  95.  
  96.     for (len = 0; scrapStr[len]; ++len)    //find length of string
  97.                     ; 
  98.  
  99.     PutScrap(len, 'TEXT', scrapStr);    //put our result string in the Clipboard
  100. }//PutRGBTextIntoScrap
  101.  
  102.  
  103. //____ ToolBoxInit __________________________________________________________________________
  104. //
  105. //    Basic initialization.
  106. //
  107. static void ToolBoxInit(void)
  108. {    
  109.     InitGraf(&qd.thePort);
  110.     InitFonts();
  111.     InitWindows();
  112.     InitMenus();
  113.     TEInit();
  114.     InitDialogs(NULL);
  115.     InitCursor();
  116.     FlushEvents(everyEvent, 0);
  117. }    //ToolBoxInit
  118.